package com.esri.core.tasks.tilecache;

import com.esri.core.internal.tasks.PollingHelper;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.internal.tasks.d;
import com.esri.core.internal.tasks.g.a;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.CallbackListener;
import com.esri.core.tasks.ags.geoprocessing.GPJobResource;

/* loaded from: classes.dex */
class RequestAndPollTileCacheTask extends d<ExportTileCacheStatus> {
    private static final long serialVersionUID = 1;
    private boolean _estimateSize;
    PollingHelper<TileCacheJobResource, GPJobResource.JobStatus> _pollingHelper;
    private TaskListener<ExportTileCacheStatus> _requestAcceptedListener;

    public RequestAndPollTileCacheTask(ExportTileCacheParameters exportTileCacheParameters, String str, UserCredentials userCredentials) {
        super(exportTileCacheParameters, str, userCredentials);
        this._pollingHelper = new PollingHelper<>();
    }

    public RequestAndPollTileCacheTask(ExportTileCacheParameters exportTileCacheParameters, String str, UserCredentials userCredentials, TaskListener<ExportTileCacheStatus> taskListener, TaskListener<ExportTileCacheStatus> taskListener2) {
        super(exportTileCacheParameters, str, userCredentials, taskListener2);
        this._pollingHelper = new PollingHelper<>();
        this._requestAcceptedListener = taskListener;
    }

    public void setStatusCallback(ExportTileCacheStatusCallback exportTileCacheStatusCallback, CallbackListener<?> callbackListener) {
        this._pollingHelper.a(exportTileCacheStatusCallback, callbackListener);
    }

    public boolean isEstimateSize() {
        return this._estimateSize;
    }

    public void setEstimateSize(boolean z) {
        this._estimateSize = z;
    }

    @Override // com.esri.core.internal.tasks.a
    public ExportTileCacheStatus execute() throws Exception {
        UserCredentials credentials = getCredentials();
        a aVar = new a((ExportTileCacheParameters) getActionInput(), getServiceURL(), credentials, new TaskListener<String>() { // from class: com.esri.core.tasks.tilecache.RequestAndPollTileCacheTask.1
            @Override // com.esri.core.internal.tasks.TaskListener
            public void onCompletion(short s, String str) {
            }

            @Override // com.esri.core.internal.tasks.TaskListener
            public void onError(Throwable th) {
                TaskListener<ExportTileCacheStatus> listener = RequestAndPollTileCacheTask.this.getListener();
                if (listener != null) {
                    listener.onError(th);
                    listener.onCompletion((short) -1, null);
                }
            }
        });
        boolean z = this._estimateSize;
        if (z) {
            aVar.a(z);
        }
        String execute = aVar.execute();
        TaskListener<ExportTileCacheStatus> taskListener = this._requestAcceptedListener;
        if (taskListener != null) {
            taskListener.onCompletion((short) 1, new ExportTileCacheStatus(getServiceURL(), execute));
        }
        return new ExportTileCacheStatus(this._pollingHelper.a(5000L, getServiceURL(), credentials, GPJobResource.JobStatus.NEW_JOB, new TileCacheLayerStatusPollHelper(execute)), getServiceURL());
    }
}
